package ua.kpi.javatraining.university;

public class Curriculum {
    private MiniCollection<Lesson> lessons;

    public Curriculum() {
        lessons = new MiniArrayList<Lesson>();
    }

    public void addLesson(Lesson lesson) {
        lessons.add(lesson);
    }

    public String getCurriculum() {
        StringBuilder sb = new StringBuilder("University curriculum");

        if (lessons.isEmpty()) {
            sb.append(" is empty");
            return sb.toString();
        }
        sb.append("\n");
        for (Object o : lessons.toArray()) {
            Lesson lesson = (Lesson) o;

            sb.append(lesson.getTopic().getName());
            sb.append(" by ");
            sb.append(lesson.getLecturer().getName().getFirstName());
            sb.append(" ");
            sb.append(lesson.getLecturer().getName().getSecondName());
            sb.append(" for group ");
            sb.append(lesson.getGroup().getName());
            sb.append(" will be held in auditory ");
            sb.append(lesson.getAuditory());
            sb.append("\n");
        }
        return sb.toString();
    }

    public String getCurriculum(AcademicGroup academicGroup) {
        StringBuilder sb = new StringBuilder("Curriculum for ");

        sb.append(academicGroup.getName());
        if (lessons.isEmpty()) {
            sb.append(" is empty");
            return sb.toString();
        }
        sb.append("\n");

        for (Object o : lessons.toArray()) {
            Lesson lesson = (Lesson) o;

            if (lesson.getGroup().equals(academicGroup)) {
                sb.append(lesson.getTopic().getName());
                sb.append(" by ");
                sb.append(lesson.getLecturer().getName().getFirstName());
                sb.append(" ");
                sb.append(lesson.getLecturer().getName().getSecondName());
                sb.append(" will be held in auditory ");
                sb.append(lesson.getAuditory());
                sb.append("\n");
            }
        }
        return sb.toString();
    }

    public String getCurriculum(Student student) {
        StringBuilder sb = new StringBuilder("Curriculum for ");

        sb.append(student.getName());
        sb.append(" from group ");
        sb.append(student.getGroup().getName());
        if (lessons.isEmpty()) {
            sb.append(" is empty");
            return sb.toString();
        }
        sb.append("\n");
        for (Object o : lessons.toArray()) {
            Lesson lesson = (Lesson) o;

            if (lesson.getGroup().equals(student.getGroup())) {
                sb.append(lesson.getTopic().getName());
                sb.append(" by ");
                sb.append(lesson.getLecturer().getName().getFirstName());
                sb.append(" ");
                sb.append(lesson.getLecturer().getName().getSecondName());
                sb.append(" will be held in auditory ");
                sb.append(lesson.getAuditory());
                sb.append("\n");
            }
        }
        return sb.toString();
    }
}
